﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class FormPipeAlignMent : System.Windows.Forms.Form
	{
		public FormPipeAlignMent()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			string[] pipeAlignmentText = this.userSetting.GetPipeAlignmentText();
			if (pipeAlignmentText[0] != null && pipeAlignmentText[0] == "横基准")
			{
				this.radioButtonLI.Checked = true;
				this.radioButtonHeng.Checked = true;
				if (pipeAlignmentText[1] != null)
				{
					if (pipeAlignmentText[1] == "顶对齐")
					{
						this.radioButtonTOP.Checked = true;
						return;
					}
					if (pipeAlignmentText[1] == "中线对齐")
					{
						this.radioButtonMiddle.Checked = true;
						return;
					}
					if (pipeAlignmentText[1] == "底对齐")
					{
						this.radioButtonBottom.Checked = true;
						return;
					}
					this.radioButtonREFE.Checked = true;
					return;
				}
			}
			else
			{
				this.radioButtonHeng.Checked = true;
				this.radioButtonLI.Checked = true;
				if (pipeAlignmentText[1] == "立对正")
				{
					this.radioButtonLIDUIZHENG.Checked = true;
					return;
				}
				if (pipeAlignmentText[1] == "上")
				{
					this.radioButtonshang.Checked = true;
					return;
				}
				if (pipeAlignmentText[1] == "下")
				{
					this.radioButtonxia.Checked = true;
					return;
				}
				if (pipeAlignmentText[1] == "左")
				{
					this.radioButtonzuo.Checked = true;
					return;
				}
				this.radioButtonyou.Checked = true;
			}
		}

		private Image getImage(string me)
		{
			return Image.FromFile(Path.Combine(Product.ResLocation, me + ".png"));
		}

		public void changeImageLi()
		{
			if (this.radioButtonLIDUIZHENG.Checked)
			{
				this.pictureBox1.Image = this.getImage("SGDZLIDUIQI");
				this.labelSpeak.Text = "水管与基准立管进行对正，即横管的中心线与立管的中心线相交（带坡度的水管也可以对正）。";
			}
			if (this.radioButtonzuo.Checked)
			{
				this.pictureBox1.Image = this.getImage("SGDZZUO");
				this.labelSpeak.Text = "立管的左边缘对齐，如图所示。即左管壁的切线在一个垂直平面上，选择管道均需为立管。";
			}
			if (this.radioButtonyou.Checked)
			{
				this.pictureBox1.Image = this.getImage("SGDZYOU");
				this.labelSpeak.Text = "立管的右边缘对齐，如图所示。即右管壁的切线在一个垂直平面上，选择管道均需为立管。";
			}
			if (this.radioButtonshang.Checked)
			{
				this.pictureBox1.Image = this.getImage("SGDZSHANG");
				this.labelSpeak.Text = "立管的上边缘对齐，如图所示。即上管壁的切线在一个垂直平面上，选择管道均需为立管。";
			}
			if (this.radioButtonxia.Checked)
			{
				this.pictureBox1.Image = this.getImage("SGDZXIA");
				this.labelSpeak.Text = "立管的下边缘对齐，如图所示。即下管壁的切线在一个垂直平面上，选择管道均需为立管。";
			}
		}

		public void changeImageHeng()
		{
			if (this.radioButtonTOP.Checked)
			{
				this.pictureBox2.Image = this.getImage("SGDZDING");
				this.labelSpeak.Text = "水管的顶部对齐，即两根水管的顶部最高点在一个水平面上（不支持带坡度的管道）。";
			}
			if (this.radioButtonMiddle.Checked)
			{
				this.pictureBox2.Image = this.getImage("SGDZZHONG");
				this.labelSpeak.Text = "水管的中心线对齐，即两根水管的中心线在一个水平面上（不支持带坡度的管道）。";
			}
			if (this.radioButtonBottom.Checked)
			{
				this.pictureBox2.Image = this.getImage("SGDZDI");
				this.labelSpeak.Text = "水管的底部对齐，即两根水管的底部最低点在一个水平面上（不支持带坡度的管道）。";
			}
			if (this.radioButtonREFE.Checked)
			{
				this.pictureBox2.Image = this.getImage("SGDZXIAN");
				this.labelSpeak.Text = "依据水管两个边线或者中心线进行对齐，在精细模式下选择水管的时候鼠标点击的位置靠近哪根就按哪根线为参考边线。";
			}
		}

		private void updateStartPosition()
		{
			if (this.radioButtonHeng.Checked)
			{
				this.groupBox3.Controls.Add(this.groupBox2);
				this.groupBox3.Controls.Remove(this.groupBox1);
				this.groupBox2.Location = new System.Drawing.Point(6, 36);
				this.groupBox1.Location = new System.Drawing.Point(299, 34);
				if (!this.radioButtonTOP.Checked && !this.radioButtonMiddle.Checked && !this.radioButtonBottom.Checked && !this.radioButtonREFE.Checked)
				{
					this.radioButtonTOP.Checked = true;
				}
				this.changeImageHeng();
				return;
			}
			this.groupBox3.Controls.Add(this.groupBox1);
			this.groupBox3.Controls.Remove(this.groupBox2);
			this.groupBox1.Location = new System.Drawing.Point(6, 36);
			this.groupBox2.Location = new System.Drawing.Point(299, 34);
			if (!this.radioButtonLIDUIZHENG.Checked && !this.radioButtonzuo.Checked && !this.radioButtonyou.Checked && !this.radioButtonshang.Checked && !this.radioButtonxia.Checked)
			{
				this.radioButtonLIDUIZHENG.Checked = true;
			}
			this.changeImageLi();
		}

		private void radioButtonHeng_CheckedChanged(object sender, EventArgs e)
		{
			this.updateStartPosition();
		}

		private void radioButtonLI_CheckedChanged(object sender, EventArgs e)
		{
			this.updateStartPosition();
		}

		private void buttonOK_Click(object sender, EventArgs e)
		{
			if (this.radioButtonHeng.Checked)
			{
				this.style = "横基准";
				if (this.radioButtonTOP.Checked)
				{
					this.message = "顶对齐";
				}
				if (this.radioButtonMiddle.Checked)
				{
					this.message = "中线对齐";
				}
				if (this.radioButtonBottom.Checked)
				{
					this.message = "底对齐";
				}
				if (this.radioButtonREFE.Checked)
				{
					this.message = "参考线对齐";
				}
			}
			else if (this.radioButtonLI.Checked)
			{
				this.style = "立基准";
				if (this.radioButtonLIDUIZHENG.Checked)
				{
					this.message = "立对正";
				}
				if (this.radioButtonzuo.Checked)
				{
					this.message = "左";
				}
				if (this.radioButtonyou.Checked)
				{
					this.message = "右";
				}
				if (this.radioButtonshang.Checked)
				{
					this.message = "上";
				}
				if (this.radioButtonxia.Checked)
				{
					this.message = "下";
				}
			}
			string[] texts = new string[]
			{
				this.style,
				this.message
			};
			this.userSetting.WritePipeAlignmentText(texts);
			base.DialogResult = DialogResult.OK;
		}

		private void radioButtonTOP_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageHeng();
		}

		private void radioButtonMiddle_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageHeng();
		}

		private void radioButtonBottom_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageHeng();
		}

		private void radioButtonREFE_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageHeng();
		}

		private void radioButtonLIDUIZHENG_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageLi();
		}

		private void radioButtonshang_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageLi();
		}

		private void radioButtonxia_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageLi();
		}

		private void radioButtonzuo_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageLi();
		}

		private void radioButtonyou_CheckedChanged(object sender, EventArgs e)
		{
			this.changeImageLi();
		}

		private void buttonESC_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		public string style = "";

		public string message = "";

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
